package cn.lmxdev.service.impl;

import cn.lmxdev.model.httpVO.FaceCodeVO;
import cn.lmxdev.service.IFaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

@Service
public class FaceServiceImpl implements IFaceService {
    @Autowired
    private RestTemplate restTemplate = null;

    @Override
    public FaceCodeVO getFaceCode(String faceBase64, String model) {
        // 请求地址
        String url = "http://81.71.165.233:7773/face_data_get/";

        // 构建请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 构建请求体
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("faceBase64", faceBase64);
        hashMap.put("model", model);

        // 发起请求
        HttpEntity<HashMap<String, String>> requestEntity = new HttpEntity<>(hashMap, headers);
        ResponseEntity<FaceCodeVO> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, FaceCodeVO.class);
        return response.getBody();
    }
}
